package com.softao.ming.gde.core.launcher;

import java.io.File;

import org.eclipse.core.runtime.CoreException;

import com.softao.ming.gde.core.BundleRegistry;

/**
 * Defines context whiling launching.
 */
public class LauncherContext {
	private final BundleRegistry mBundleRegistry;
	private final LauncherSettings mSettings;
	
	/**
	 * @param settings settings of the launcher
	 * @throws CoreException
	 */
	public LauncherContext(LauncherSettings settings) throws CoreException {
		mSettings = settings;
		mBundleRegistry = new BundleRegistry();
		
		if (settings.getPlatformLocations() != null) {
			for (String location : settings.getPlatformLocations()) {
				File pluginFolder = new File(location, "plugins");
				mBundleRegistry.registryDirectory(pluginFolder);
			}
		}
		
		if (settings.getProjectLocations() != null) {
			for (String location : settings.getProjectLocations()) {
				File rootFolder = new File(location);
				for (File projectFolder : rootFolder.listFiles()) {
					mBundleRegistry.registrySingle(projectFolder);
				}
			}
		}
	}
	
	/**
	 * @return the bundleRegistry
	 */
	public BundleRegistry getBundleRegistry() {
		return mBundleRegistry;
	}
	
	/**
	 * @return the settings
	 */
	public LauncherSettings getSettings() {
		return mSettings;
	}
}
